<?php

// php configuration
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('Europe/Paris');

ini_set('include_path', '../library');

// Use autoload
require 'Zend/Loader.php';
Zend_Loader::registerAutoLoad();

// Session start
Zend_Session::start();

// Load configuration
$config = new Zend_Config_Ini(
    '../application/config/production.ini',
    'production',
    array('allowModifications' => true)
);

if (isset($_SERVER['PLATFORM']) && $_SERVER['PLATFORM'] == 'dev') {
    $config->merge(
        new Zend_Config_Ini('../application/config/dev.ini', 'dev')
    );
}

// Start mvc using layout
Zend_Layout::startMvc($config->layout->toArray());

// Sets default view rendering options for all controllers
$viewRenderer =
    Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView(new Zend_View());
$viewRenderer->view->doctype('XHTML1_STRICT');
$viewRenderer->view->setEncoding('utf-8');
$viewRenderer->view->setLfiProtection(false);
$viewRenderer->view->addScriptPath('../application/default/views/scripts');

// Database connection
$db = Zend_Db::factory($config->database->adapter,
                        $config->database->params->toArray());
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
Zend_Registry::set('config', $config);

// Sets dir for custom helpers and Zend helpers
Zend_Controller_Action_HelperBroker::addPath(
    Zend_Registry::get('config')
        ->paths
        ->library . '/Helpers', 'Helper');

// Load the front controller
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(array(
    'default' => '../application/default/controllers',
    'user' => '../application/user/controllers',
    'admin' => '../application/admin/controllers',
    ));
$front->throwExceptions($config->exceptions->throw);

$front->dispatch();
